﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Lib.CommonForm;

namespace AUI
{
    public partial class frmCustomerInfo : FormBase
    {
        int _CustomerId = 0;
        DataRow m_dr;
        public frmCustomerInfo(DataRow dr)
        {
            InitializeComponent();
            

            this.txtCustomerCode.MaxLength = tbl_Customers_Length.CustomerCode;
            this.txtCustomerName.MaxLength = tbl_Customers_Length.CustomerName;
            this.txtAddress.MaxLength = tbl_Customers_Length.Address;
            this.txtEmail.MaxLength = tbl_Customers_Length.Email;
            this.txtPhone.MaxLength = tbl_Customers_Length.Phone;
            this.txtMobile.MaxLength = tbl_Customers_Length.Mobile;
            this.txtFax.MaxLength = tbl_Customers_Length.Fax;

            _listRole = tbl_RoleRight_Controller.Instance().GetInfo("KhachHang");
            FormGlobals.Control_SetRequired(txtCustomerCode, txtCustomerName, cboBranchId);
            LoadComboBox.BranchID_Input(cboBranchId);
            m_dr = dr;
            if (m_dr != null)
            {
                FormGlobals.Panel_FillData(this, dr);
                _CustomerId = Globals.ToInt32(dr["CustomerId"]);
            }
            
            _IsLoading = false;
        }
        public override void Show_Form()
        {
            this.ShowDialog();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            tbl_Customers_Info i = new tbl_Customers_Info();
            FormGlobals.Panel_GetData(this, i);
            i.CustomerId = _CustomerId;
            i.CreateUser = FormGlobals.strUserName;
            i.LastUser = FormGlobals.strUserName;
            _CustomerId = tbl_Customers_Controller.Instance().Save(i);
            if (_CustomerId > 0)
            {
                FormGlobals.Message_InTaskbar(UIMessage.SAVE_COMPLETE);
                _dlgResult = DialogResult.OK;
                this.Close();
            }
        }
    }
}
